fn main() {
    println!("泛型空约束");

    struct Cardinal;
    struct BlueJay;
    struct Turkey;

    trait Red {}
    trait Blue {}

    impl Red for Cardinal {}
    impl Blue for BlueJay {}

    // 这些函数只对实现了相应的 trait 的类型有效
    // 这些 trait 是空的, 但是没关系
    fn red<T: Red>(_: &T) -> &'static str {
        "red"
    }
    fn blue<T: Blue>(_: &T) -> &'static str {
        "blue"
    }

    let cardinal = Cardinal {};
    println!("{}", red(&cardinal));

    let bluejay = BlueJay {};
    println!("{}", blue(&bluejay));

    // 由于约束，`red()` 不能作用于 blue_jay （蓝松鸟），反过来也一样
    let _turkey = Turkey {};
    // println!("{}", red(&_turkey)); // the trait `Red` is not implemented for `Turkey`
}
